package com.grakol.parallel.samples.tests;

import com.grakol.parallel.samples.IFunction;

public class CompareFibonacci {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if( args.length < 1 ) {
			System.out.println( "usage: CompareFibonacci input_number" );
			return;
		}
		long inputNo = Long.valueOf( args[0] );
		// test using iterative version
		IFunction<Long> iFunction = new FibonacciFunction( inputNo, true );
		// measure execution time
		long startTime = System.nanoTime();
		iFunction.perform();
		long result = iFunction.getResult();
		long timeElapsedMs = (System.nanoTime() - startTime)/1000000;
		// print result for 1 thread
		System.out.println( "Iterative: Fib(" + inputNo + ") = " + result + " [" + timeElapsedMs + " ms]" );
		// test using recursive version
		IFunction<Long> rFunction = new FibonacciFunction( inputNo );
		// measure execution time
		startTime = System.nanoTime();
		rFunction.perform();
		result = rFunction.getResult();
		timeElapsedMs = (System.nanoTime() - startTime)/1000000;
		// print result for 1 thread
		System.out.println( "Recursive: Fib(" + inputNo + ") = " + result + " [" + timeElapsedMs + " ms]" );
	}

}
